package com.yzq.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import java.util.Properties;

@Configuration
public class MailConfig {

    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost("smtp.163.com");
        mailSender.setPort(465);
        mailSender.setUsername("yezhiqiang2023@163.com");
        mailSender.setPassword("LCiaxx9HfULeezfb");

        Properties props = mailSender.getJavaMailProperties();
        props.put("mail.smtp.ssl.enable", "true"); // 开启SSL加密
        props.put("mail.smtp.auth", "true"); // 开启认证
        props.put("mail.smtp.connectiontimeout", "5000"); // 设置连接超时时间
        props.put("mail.smtp.timeout", "5000"); // 设置读取超时时间
        props.put("mail.smtp.writetimeout", "5000"); // 设置写入超时时间

        return mailSender;
    }
}